<?php

/**
 * 微信登录
 */

namespace app\wechat\mobile;

class LoginMobile extends \app\wechat\common\WechatCommon {

    protected $oauth = null;

    public function __construct() {
        parent::__construct();
        $this->oauth = $this->wechat->oauth;
    }

    /**
     * 登录跳转
     */
    public function index() {
        $response = $this->oauth->redirect();
        $response->send();

    }

    /**
     * 回调授权
     */
    public function connect() {
        $user = $this->oauth->user();
        $url = target('member/Member', 'service')->oauthUser('wechat', $user->getId(), $user->getName(), $user->getAvatar());
        if(!$url) {
            $this->error(target('member/Member', 'service')->getError(), url('index/Index/index'));
        }
        $this->redirect($url);
    }

}